//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.WitheredFreddyTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.WitheredFreddyRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.WitheredFreddyAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.ScareTimer    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.WitheredFreddyRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.HeadShake    // Initially set via a loop in the UFO script
private alias Object.Value9 : Object.RandomLocation1    // Initially set via a loop in the UFO script
private alias Object.Value10 : Object.Cooldown    // Initially set via a loop in the UFO script
private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script

private alias Object.Value12 : Object.ScareDirection    // Initially set via a loop in the UFO script



// Game Mode Aliases
public value OfficePower = 100;

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 0 : CAM_SHOWSTAGE_0
private alias 1 : CAM_DININGHALL_1
private alias 2 : CAM_BACKSTAGE_2
private alias 3 : CAM_PIRATESCOVE_3
private alias 4 : CAM_WESTHALL_4
private alias 5 : CAM_CLOSET_5
private alias 6 : CAM_WHALLCORNER_6
private alias 7 : CAM_EASTHALL_7
private alias 8 : CAM_EHALLCORNER_8
private alias 9 : CAM_KITCHEN_9
private alias 10 : CAM_BATHROOMS_10

private alias 15 : WitheredFreddy_OFFICEDOOR
private alias 16 : WitheredFreddy_WAITTOSCARE
private alias 17 : WitheredFreddy_SCARE


private alias object.state : WitheredFreddy.State



event ObjectMain

//-1 is basically the ai level 0 ig
if Object[5].Type == TypeName[Blank Object]
	switch WitheredFreddy.state
		case 0
			if Object.Cooldown > 0
				Object.Cooldown--
			end if

			if Object.Cooldown == 0
				Object.WitheredFreddyTimer++
				Object.MoveTime = 400
				rand(temp3, 100)
				Object.MoveTime += temp3
				if Object.WitheredFreddyTimer >= Object.MoveTime 
					Rand(Object.WitheredFreddyRandom, 21)
					if Object.WitheredFreddyAI > Object.WitheredFreddyRandom 
						//these align with the cameras he goes to
						//state 10 is cam 10
						//15+ is at the office watch out

							if Object[6].value1 == WitheredFreddy.state
								object[6].alpha = 355
							end if


							rand(Object.RandomLocation1, 2)

							switch WitheredFreddy.state
							case 0	//showstage
								if Object.RandomLocation1 >= 1
									PlaySfx(SfxName[MetalLeftQuiet], 0)	
									WitheredFreddy.state = CAM_WESTHALL_4
								else
									PlaySfx(SfxName[MetalRightQuiet], 0)	
									WitheredFreddy.state = CAM_EASTHALL_7
								end if
							break
							end switch	

							if Object[6].value1 == WitheredFreddy.state
								object[6].alpha = 355
							end if	
							

					end if
					Object.WitheredFreddyTimer = 0	
				end if
			end if	
		break
		case CAM_WESTHALL_4
			Object.WitheredFreddyTimer++
			Object.MoveTime = 300
			rand(temp3, 100)
			Object.MoveTime += temp3
			if Object.WitheredFreddyTimer >= Object.MoveTime 
				Rand(Object.WitheredFreddyRandom, 21)
				if Object.WitheredFreddyAI > Object.WitheredFreddyRandom 
					//these align with the cameras he goes to
					//state 10 is cam 10
					//15+ is at the office watch out

						if Object[6].value1 == WitheredFreddy.state
							object[6].alpha = 355
						end if


						rand(Object.RandomLocation1, 2)
						Object.ScareDirection = 1

						if LeftDoorClosed == 1
							PlaySfx(SfxName[BlockL], 0)
							Object.Cooldown = 600
							object.state = 0
						else
							Object[18].HeadShake = -200
							StopMusic()
							PlaySfx(SfxName[Scream2], 0)								
							object.state = 17	
						end if

						if Object[6].value1 == WitheredFreddy.state
							object[6].alpha = 355
						end if	
						

				end if
				Object.WitheredFreddyTimer = 0	
			end if
		break
		case CAM_EASTHALL_7
			Object.WitheredFreddyTimer++
			Object.MoveTime = 300
			rand(temp3, 100)
			Object.MoveTime += temp3
			if Object.WitheredFreddyTimer >= Object.MoveTime 
				Rand(Object.WitheredFreddyRandom, 21)
				if Object.WitheredFreddyAI > Object.WitheredFreddyRandom 
					//these align with the cameras he goes to
					//state 10 is cam 10
					//15+ is at the office watch out

						if Object[6].value1 == WitheredFreddy.state
							object[6].alpha = 355
						end if

						rand(Object.RandomLocation1, 2)

						if RightDoorClosed == 1
							PlaySfx(SfxName[BlockR], 0)
							Object.Cooldown = 600
							object.state = 0
						else
							Object[18].HeadShake = screen.xcenter
							StopMusic()
							PlaySfx(SfxName[Scream2], 0)							
							object.state = 17	
						end if


						if Object[6].value1 == WitheredFreddy.state
							object[6].alpha = 355
						end if	
						

				end if
				Object.WitheredFreddyTimer = 0	
			end if
		break		
		case 17
			PlayerJumpscared = 1
			if Object.WitheredFreddyRise > -100
				Object.WitheredFreddyRise -= 16
			else
				Object.WitheredFreddyRise = -100
			end if
		break			
	end switch
end if	
end event

event ObjectDraw

//	DrawNumbers(0, 32, 96, WitheredFreddy.state, 3, 8, 0)

//	DrawNumbers(0, 64, 96, Object.Cooldown, 3, 8, 0)

//	DrawNumbers(0, 96, 96, Object.ScareTimer, 3, 8, 0)


	if Object.Tweak == 1
		rand(Object.HeadShake, 6)
	end if	

	if WitheredFreddy.state == 17
		if Object.ScareDirection == 0
			if Object.Tweak == 0
				temp0 = screen.xsize
				temp0 -= screen.xsize
				if Object.HeadShake > temp0
					Object.HeadShake -= 20
				else
					Object.Tweak = 1
				end if
			end if	
		else
			if Object.Tweak == 0
				temp0 = screen.xsize
				temp0 -= screen.xsize
				if Object.HeadShake < temp0
					Object.HeadShake += 20
				else
					Object.Tweak = 1
				end if
			end if			
		end if

		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140

		temp2 = temp1
		temp2 += Object.HeadShake

		DrawSpriteScreenFX(10, FX_SCALE, temp2, Object.WitheredFreddyRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp2, Object.WitheredFreddyRise)	//head
	end if

	

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[18].Type = TypeName[WitheredFreddy]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[18].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[18].DrawOrder = 5

	Object[18].HeadShake = screen.xcenter

	Object[18].Cooldown = 600

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	
	SpriteFrame(-38, 280, 352, 91, 1161, 600)
	SpriteFrame(46, 100, 188, 221, 1161, 692)	//11


end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
